/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author user1
 */
import java.util.Scanner;

public class ParameterChi extends Parameter {

    Scanner input = new Scanner(System.in);
    public double r;

    public void ParameterChi() {
        System.out.println("Batas Bawah : ");
        lower = input.nextDouble();
        
        System.out.println("Batas Atas : ");
        upper = input.nextDouble();
        
        System.out.println("Derajat Bebas : ");
        r = input.nextDouble();
        
        
        }
    
    

    public static double faktorial(double n) {
        if (n == 0 || n == 1.0) {
            return 1;
        } else {
            return n * faktorial(n - 1);
        }
    }

    @Override
    public double F(double x) {
        double chi;
        chi = (Math.pow(x, (this.r / 2) - 1)) * (Math.pow(Math.E, -x / 2)) / (faktorial((this.r / 2) - 1)) * Math.pow(2, this.r / 2);
        return chi;

    }

    @Override
    public void integral() {
        double x = 0;
        for(double i = lower+0.05; i<upper; i=i+0.05){
            x =F(i)+x;
                }
        double integral = 0.5 * 0.05 * (F(lower) + 2*x + F(upper));
        System.out.println("Nilai pdf distribusi chi square adalah "+integral);        
    }

    public double getR() {
        return this.r;
    }
    @Override
    public void standarDeviasi() {
        System.out.println("Standar Deviasi Distribusi Chi-Square = "+Math.sqrt(2*r));
    }
}